<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="../Universal.css">
</head>
<body>
    
    <div id="cnblogs_post_body" class="blogpost-body">
        <h2>Map接口</h2>
    <p>通过查看Map接口描述，发现Map接口下的集合与Collection接口下的集合，它们存储数据的形式不同，如下图。</p>
    <p><img src="https://images2015.cnblogs.com/blog/612774/201707/612774-20170714173424931-631628670.png" alt=""></p>
    <p>Collection中的集合，元素是孤立存在的（理解为单身），向集合中存储元素采用一个个元素的方式存储。</p>
    <p>Map中的集合，元素是成对存在的(理解为夫妻)。每个元素由键与值两部分组成，通过键可以找对所对应的值。</p>
    <p>Collection中的集合称为单列集合，Map中的集合称为双列集合。</p>
    <p>需要注意的是，Map中的集合不能包含重复的键，值可以重复；每个键只能对应一个值。</p>
    <p>Map中常用的集合为HashMap集合、LinkedHashMap集合。</p>
    <h3>Map接口中常用集合概述</h3>
    <p>通过查看Map接口描述，看到Map有多个子类，这里我们主要讲解常用的HashMap集合、LinkedHashMap集合。</p>
    <ul>
    <li>HashMap&lt;K,V&gt;：存储数据采用的哈希表结构，元素的存取顺序不能保证一致。由于要保证键的唯一、不重复，需要重写键的hashCode()方法、equals()方法。</li>
    <li>LinkedHashMap&lt;K,V&gt;：HashMap下有个子类LinkedHashMap，存储数据采用的哈希表结构+链表结构。通过链表结构可以保证元素的存取顺序一致；通过哈希表结构可以保证的键的唯一、不重复，需要重写键的hashCode()方法、equals()方法。</li>
    </ul>
    <p>注意：Map接口中的集合都有两个泛型变量&lt;K,V&gt;,在使用时，要为两个泛型变量赋予数据类型。两个泛型变量&lt;K,V&gt;的数据类型可以相同，也可以不同。</p>
    <h3>Map接口中的常用方法</h3>
    <p><img src="https://images2015.cnblogs.com/blog/612774/201707/612774-20170714174012806-592208026.png" alt=""></p>
    <p>put方法：将指定的键与值对应起来，并添加到集合中，方法返回值为键所对应的值。</p>
    <ul>
    <li>使用put方法时，若指定的键(key)在集合中没有，则没有这个键对应的值，返回null，并把指定的键值添加到集合中；</li>
    <li>使用put方法时，若指定的键(key)在集合中存在，则返回值为集合中键对应的值（该值为替换前的值），并把指定键所对应的值，替换成指定的新值。</li>
    </ul>
    <p>get方法：获取指定键(key)所对应的值(value)</p>
    <p>remove方法：根据指定的键(key)删除元素，返回被删除元素的值(value)。</p>
    <p>Map接口的方法演示</p>
    <div class="cnblogs_code">
    <pre><span style="color: rgba(0, 0, 255, 1)">public</span> <span style="color: rgba(0, 0, 255, 1)">class</span><span style="color: rgba(0, 0, 0, 1)"> MapDemo {
        </span><span style="color: rgba(0, 0, 255, 1)">public</span> <span style="color: rgba(0, 0, 255, 1)">static</span> <span style="color: rgba(0, 0, 255, 1)">void</span><span style="color: rgba(0, 0, 0, 1)"> main(String[] args) {
    </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">创建Map对象</span><span style="color: rgba(0, 0, 0, 1)">
            Map</span>&lt;String, String&gt; map = <span style="color: rgba(0, 0, 255, 1)">new</span> HashMap&lt;String,String&gt;<span style="color: rgba(0, 0, 0, 1)">();
    </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">给map中添加元素</span><span style="color: rgba(0, 0, 0, 1)">
            map.put(</span><span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">星期一</span><span style="color: rgba(128, 0, 0, 1)">"</span>, <span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">Monday</span><span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(0, 0, 0, 1)">);
            map.put(</span><span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">星期日</span><span style="color: rgba(128, 0, 0, 1)">"</span>, <span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">Sunday</span><span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(0, 0, 0, 1)">);
            System.</span><span style="color: rgba(0, 0, 255, 1)">out</span>.println(map); <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)"> {星期日=Sunday, 星期一=Monday}
    </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">当给Map中添加元素，会返回key对应的原来的value值，若key没有对应的值，返回null</span><span style="color: rgba(0, 0, 0, 1)">
            System.</span><span style="color: rgba(0, 0, 255, 1)">out</span>.println(map.put(<span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">星期一</span><span style="color: rgba(128, 0, 0, 1)">"</span>, <span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">Mon</span><span style="color: rgba(128, 0, 0, 1)">"</span>)); <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)"> Monday</span><span style="color: rgba(0, 0, 0, 1)">
            System.</span><span style="color: rgba(0, 0, 255, 1)">out</span>.println(map); <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)"> {星期日=Sunday, 星期一=Mon}
    </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">根据指定的key获取对应的value</span><span style="color: rgba(0, 0, 0, 1)">
            String en </span>= map.<span style="color: rgba(0, 0, 255, 1)">get</span>(<span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">星期日</span><span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(0, 0, 0, 1)">);
            System.</span><span style="color: rgba(0, 0, 255, 1)">out</span>.println(en); <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)"> Sunday
    </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">根据key删除元素,会返回key对应的value值</span><span style="color: rgba(0, 0, 0, 1)">
            String value </span>= map.remove(<span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">星期日</span><span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(0, 0, 0, 1)">);
            System.</span><span style="color: rgba(0, 0, 255, 1)">out</span>.println(value); <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)"> Sunday</span><span style="color: rgba(0, 0, 0, 1)">
            System.</span><span style="color: rgba(0, 0, 255, 1)">out</span>.println(map); <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)"> {星期一=Mon}</span><span style="color: rgba(0, 0, 0, 1)">
        }
    }</span></pre>
    </div>
    <h3>Map集合遍历键找值方式</h3>
    <p>键找值方式：即通过元素中的键，获取键所对应的值。</p>
    <p>操作步骤与图解：</p>
    <ul>
    <li>1.获取Map集合中所有的键，由于键是唯一的，所以返回一个Set集合存储所有的键</li>
    </ul>
    <p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<img src="https://images2015.cnblogs.com/blog/612774/201707/612774-20170714174037415-1643553317.png" alt=""></p>
    <ul>
    <li>2.遍历键的Set集合，得到每一个键</li>
    <li>3.根据键，获取键所对应的值</li>
    </ul>
    <p><img src="https://images2015.cnblogs.com/blog/612774/201707/612774-20170714174128447-1853989940.png" alt=""></p>
    <p>代码演示：</p>
    <div class="cnblogs_code">
    <pre><span style="color: rgba(0, 0, 255, 1)">public</span> <span style="color: rgba(0, 0, 255, 1)">class</span><span style="color: rgba(0, 0, 0, 1)"> MapDemo {
        </span><span style="color: rgba(0, 0, 255, 1)">public</span> <span style="color: rgba(0, 0, 255, 1)">static</span> <span style="color: rgba(0, 0, 255, 1)">void</span><span style="color: rgba(0, 0, 0, 1)"> main(String[] args) {
    </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">创建Map对象</span><span style="color: rgba(0, 0, 0, 1)">
            Map</span>&lt;String, String&gt; map = <span style="color: rgba(0, 0, 255, 1)">new</span> HashMap&lt;String,String&gt;<span style="color: rgba(0, 0, 0, 1)">();
    </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">给map中添加元素</span><span style="color: rgba(0, 0, 0, 1)">
            map.put(</span>"邓超", "孙俪"<span style="color: rgba(0, 0, 0, 1)">);
            map.put(</span>"李晨", "范冰冰"<span style="color: rgba(0, 0, 0, 1)">);
            map.put(</span>"刘德华", "柳岩"<span style="color: rgba(0, 0, 0, 1)">);
    </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">获取Map中的所有key</span><span style="color: rgba(0, 0, 0, 1)">
            Set</span>&lt;String&gt; keySet =<span style="color: rgba(0, 0, 0, 1)"> map.keySet();
    </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">遍历存放所有key的Set集合</span><span style="color: rgba(0, 0, 0, 1)">
            Iterator</span>&lt;String&gt; it =<span style="color: rgba(0, 0, 0, 1)">keySet.iterator();
            </span><span style="color: rgba(0, 0, 255, 1)">while</span><span style="color: rgba(0, 0, 0, 1)">(it.hasNext()){
    </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">得到每一个key</span><span style="color: rgba(0, 0, 0, 1)">
                String key </span>=<span style="color: rgba(0, 0, 0, 1)"> it.next();
    </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">通过key获取对应的value</span><span style="color: rgba(0, 0, 0, 1)">
                String value </span>=<span style="color: rgba(0, 0, 0, 1)"> map.get(key);
                System.out.println(key</span>+"="+<span style="color: rgba(0, 0, 0, 1)">value);
            }
        }
    }</span></pre>
    </div>
    <h3>Entry键值对对象</h3>
    <p><img src="https://images2015.cnblogs.com/blog/612774/201707/612774-20170714174335087-468052561.png" alt=""></p>
    <p><img src="https://images2015.cnblogs.com/blog/612774/201707/612774-20170714174349743-718860442.png" alt=""></p>
    <p>在Map类设计时，提供了一个嵌套接口：Entry。Entry将键值对的对应关系封装成了对象。即键值对对象，这样我们在遍历Map集合时，就可以从每一个键值对（Entry）对象中获取对应的键与对应的值。</p>
    <p>Entry是Map接口中提供的一个静态内部嵌套接口。</p>
    <ul>
    <li>getKey()方法：获取Entry对象中的键</li>
    <li>getValue()方法：获取Entry对象中的值</li>
    <li>entrySet()方法：用于返回Map集合中所有的键值对(Entry)对象，以Set集合形式返回。</li>
    </ul>
    <h3>Map集合遍历键值对方式</h3>
    <p>键值对方式：即通过集合中每个键值对(Entry)对象，获取键值对(Entry)对象中的键与值。</p>
    <p>操作步骤与图解：</p>
    <ul>
    <li>1.获取Map集合中，所有的键值对(Entry)对象，以Set集合形式返回。</li>
    </ul>
    <p>　　　　<img src="https://images2015.cnblogs.com/blog/612774/201707/612774-20170714174410775-1290987132.png" alt=""></p>
    <ul>
    <li>2.遍历包含键值对(Entry)对象的Set集合，得到每一个键值对(Entry)对象</li>
    <li>3.通过键值对(Entry)对象，获取Entry对象中的键与值。</li>
    </ul>
    <p>　　　　<img src="https://images2015.cnblogs.com/blog/612774/201707/612774-20170714174422775-2133121556.png" alt=""></p>
    <div class="cnblogs_code">
    <pre><span style="color: rgba(0, 0, 255, 1)">public</span> <span style="color: rgba(0, 0, 255, 1)">class</span><span style="color: rgba(0, 0, 0, 1)"> MapDemo {
        </span><span style="color: rgba(0, 0, 255, 1)">public</span> <span style="color: rgba(0, 0, 255, 1)">static</span> <span style="color: rgba(0, 0, 255, 1)">void</span><span style="color: rgba(0, 0, 0, 1)"> main(String[] args) {
    </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">创建Map对象</span><span style="color: rgba(0, 0, 0, 1)">
            Map</span>&lt;String, String&gt; map = <span style="color: rgba(0, 0, 255, 1)">new</span> HashMap&lt;String,String&gt;<span style="color: rgba(0, 0, 0, 1)">();
    </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">给map中添加元素</span><span style="color: rgba(0, 0, 0, 1)">
            map.put(</span>"邓超", "孙俪"<span style="color: rgba(0, 0, 0, 1)">);
            map.put(</span>"李晨", "范冰冰"<span style="color: rgba(0, 0, 0, 1)">);
            map.put(</span>"刘德华", "柳岩"<span style="color: rgba(0, 0, 0, 1)">);
    </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">获取Map中的所有key与value的对应关系</span><span style="color: rgba(0, 0, 0, 1)">
            Set</span>&lt;Map.Entry&lt;String,String&gt;&gt; entrySet =<span style="color: rgba(0, 0, 0, 1)"> map.entrySet();
    </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">遍历Set集合</span><span style="color: rgba(0, 0, 0, 1)">
            Iterator</span>&lt;Map.Entry&lt;String,String&gt;&gt; it =<span style="color: rgba(0, 0, 0, 1)">entrySet.iterator();
            </span><span style="color: rgba(0, 0, 255, 1)">while</span><span style="color: rgba(0, 0, 0, 1)">(it.hasNext()){
    </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">得到每一对对应关系</span><span style="color: rgba(0, 0, 0, 1)">
                Map.Entry</span>&lt;String,String&gt; entry =<span style="color: rgba(0, 0, 0, 1)"> it.next();
    </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">通过每一对对应关系获取对应的key</span><span style="color: rgba(0, 0, 0, 1)">
                String key </span>=<span style="color: rgba(0, 0, 0, 1)"> entry.getKey();
    </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">通过每一对对应关系获取对应的value</span><span style="color: rgba(0, 0, 0, 1)">
                String value </span>=<span style="color: rgba(0, 0, 0, 1)"> entry.getValue();
                System.out.println(key</span>+"="+<span style="color: rgba(0, 0, 0, 1)">value);
            }
        }
    }</span></pre>
    </div>
    <h4>注意：Map集合不能直接使用迭代器或者foreach进行遍历。但是转成Set之后就可以使用了。</h4>
    <h3>HashMap存储自定义类型键值</h3>
    <p>练习：每位学生（姓名，年龄）都有自己的家庭住址。那么，既然有对应关系，则将学生对象和家庭住址存储到map集合中。学生作为键, 家庭住址作为值。</p>
    <p>注意，学生姓名相同并且年龄相同视为同一名学生。</p>
    <p>学生类</p>
    <div class="cnblogs_code">
    <pre><span style="color: rgba(0, 0, 255, 1)">public</span> <span style="color: rgba(0, 0, 255, 1)">class</span><span style="color: rgba(0, 0, 0, 1)"> Student {
        </span><span style="color: rgba(0, 0, 255, 1)">private</span><span style="color: rgba(0, 0, 0, 1)"> String name;
        </span><span style="color: rgba(0, 0, 255, 1)">private</span> <span style="color: rgba(0, 0, 255, 1)">int</span><span style="color: rgba(0, 0, 0, 1)"> age;
    </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">编写构造方法，文档中已省略
    </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">编写get,set方法，文档中已省略
    </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">编写toString方法，文档中已省略</span><span style="color: rgba(0, 0, 0, 1)">
    }</span></pre>
    </div>
    <p>测试类</p>
    <div class="cnblogs_code">
    <pre><span style="color: rgba(0, 0, 255, 1)">public</span> <span style="color: rgba(0, 0, 255, 1)">class</span><span style="color: rgba(0, 0, 0, 1)"> HashMapTest {
        </span><span style="color: rgba(0, 0, 255, 1)">public</span> <span style="color: rgba(0, 0, 255, 1)">static</span> <span style="color: rgba(0, 0, 255, 1)">void</span><span style="color: rgba(0, 0, 0, 1)"> main(String[] args) {
    </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">1,创建hashmap集合对象。</span><span style="color: rgba(0, 0, 0, 1)">
            Map</span>&lt;Student,String&gt; map = <span style="color: rgba(0, 0, 255, 1)">new</span> HashMap&lt;Student,String&gt;<span style="color: rgba(0, 0, 0, 1)">();
    </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">2,添加元素。</span><span style="color: rgba(0, 0, 0, 1)">
            map.put(</span><span style="color: rgba(0, 0, 255, 1)">new</span> Student("lisi",28), "上海"<span style="color: rgba(0, 0, 0, 1)">);
            map.put(</span><span style="color: rgba(0, 0, 255, 1)">new</span> Student("wangwu",22), "北京"<span style="color: rgba(0, 0, 0, 1)">);
            map.put(</span><span style="color: rgba(0, 0, 255, 1)">new</span> Student("zhaoliu",24), "成都"<span style="color: rgba(0, 0, 0, 1)">);
            map.put(</span><span style="color: rgba(0, 0, 255, 1)">new</span> Student("zhouqi",25), "广州"<span style="color: rgba(0, 0, 0, 1)">);
            map.put(</span><span style="color: rgba(0, 0, 255, 1)">new</span> Student("wangwu",22), "南京"<span style="color: rgba(0, 0, 0, 1)">);
    </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">3,取出元素。键找值方式</span><span style="color: rgba(0, 0, 0, 1)">
            Set</span>&lt;Student&gt; keySet =<span style="color: rgba(0, 0, 0, 1)"> map.keySet();
            </span><span style="color: rgba(0, 0, 255, 1)">for</span><span style="color: rgba(0, 0, 0, 1)">(Student key : keySet){
                String value </span>=<span style="color: rgba(0, 0, 0, 1)"> map.get(key);
                System.out.println(key.toString()</span>+"....."+<span style="color: rgba(0, 0, 0, 1)">value);
            }
    </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">取出元素。键值对方式</span><span style="color: rgba(0, 0, 0, 1)">
            Set</span>&lt;Map.Entry&lt;Student, String&gt;&gt; entrySet =<span style="color: rgba(0, 0, 0, 1)"> map.entrySet();
            </span><span style="color: rgba(0, 0, 255, 1)">for</span> (Map.Entry&lt;Student, String&gt;<span style="color: rgba(0, 0, 0, 1)"> entry : entrySet) {
                Student key </span>=<span style="color: rgba(0, 0, 0, 1)"> entry.getKey();
                String value </span>=<span style="color: rgba(0, 0, 0, 1)"> entry.getValue();
                System.out.println(key.toString()</span>+"....."+<span style="color: rgba(0, 0, 0, 1)">value);
            }
        }
    }</span></pre>
    </div>
    <p>当给HashMap中存放自定义对象时，如果自定义对象作为key存在，这时要保证对象唯一，必须复写对象的hashCode和equals方法(如果忘记，请回顾HashSet存放自定义对象)。</p>
    <p>如果要保证map中存放的key和取出的顺序一致，可以使用LinkedHashMap集合来存放。</p>
    <h2>静态导入</h2>
    <p>在导包的过程中我们可以直接导入静态部分，这样某个类的静态成员就可以直接使用了。在源码中经常会出现静态导入。</p>
    <p>静态导入格式：&nbsp;<span class="cnblogs_code"><span style="color: rgba(0, 0, 255, 1)">import</span> <span style="color: rgba(0, 0, 255, 1)">static</span> XXX.YYY; </span>&nbsp;，导入后YYY可直接使用。</p>
    <p>例如：Map.Entry的访问，简化后为Entry</p>
    <div class="cnblogs_code">
    <pre><span style="color: rgba(0, 0, 255, 1)">import</span> <span style="color: rgba(0, 0, 255, 1)">static</span><span style="color: rgba(0, 0, 0, 1)"> java.util.Map.Entry;
    </span><span style="color: rgba(0, 0, 255, 1)">public</span> <span style="color: rgba(0, 0, 255, 1)">class</span><span style="color: rgba(0, 0, 0, 1)"> HashMapTest {
        </span><span style="color: rgba(0, 0, 255, 1)">public</span> <span style="color: rgba(0, 0, 255, 1)">static</span> <span style="color: rgba(0, 0, 255, 1)">void</span><span style="color: rgba(0, 0, 0, 1)"> main(String[] args) {
    </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">1,创建hashmap集合对象。</span><span style="color: rgba(0, 0, 0, 1)">
            Map</span>&lt;Student,String&gt; map = <span style="color: rgba(0, 0, 255, 1)">new</span> HashMap&lt;Student,String&gt;<span style="color: rgba(0, 0, 0, 1)">();
    </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">取出元素。键值对方式
    </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">Set&lt;Map.Entry&lt;Student, String&gt;&gt; entrySet = map.entrySet();</span><span style="color: rgba(0, 0, 0, 1)">
            Set</span>&lt;Entry&lt;Student, String&gt;&gt; entrySet =<span style="color: rgba(0, 0, 0, 1)"> map.entrySet();
    </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">for (Map.Entry&lt;Student, String&gt; entry : entrySet) {</span>
            <span style="color: rgba(0, 0, 255, 1)">for</span> (Entry&lt;Student, String&gt;<span style="color: rgba(0, 0, 0, 1)"> entry : entrySet) {
                Student key </span>=<span style="color: rgba(0, 0, 0, 1)"> entry.getKey();
                String value </span>=<span style="color: rgba(0, 0, 0, 1)"> entry.getValue();
                System.out.println(key.toString()</span>+"....."+<span style="color: rgba(0, 0, 0, 1)">value);
            }
        }
    }</span></pre>
    </div>
    <h2>可变参数</h2>
    <p>在JDK1.5之后，如果我们定义一个方法需要接受多个参数，并且多个参数类型一致，我们可以对其简化成如下格式：</p>
    <div class="cnblogs_code">
    <pre>修饰符 返回值类型 方法名(参数类型... 形参名){ }</pre>
    </div>
    <p>其实这个书写完全等价与</p>
    <div class="cnblogs_code">
    <pre>修饰符 返回值类型 方法名(参数类型[] 形参名){ }</pre>
    </div>
    <p>只是后面这种定义，在调用时必须传递数组，而前者可以直接传递数据即可。jdk1.5以后。出现了简化操作。... 用在参数上，称之为可变参数。</p>
    <p>同样是代表数组，但是在调用这个带有可变参数的方法时，不用创建数组(这就是简单之处)，直接将数组中的元素作为实际参数进行传递，其实编译成的class文件，将这些元素先封装到一个数组中，在进行传递。这些动作都在编译.class文件时，自动完成了。</p>
    <p>代码演示：</p>
    <div class="cnblogs_code">
    <pre><span style="color: rgba(0, 0, 255, 1)">public</span> <span style="color: rgba(0, 0, 255, 1)">class</span><span style="color: rgba(0, 0, 0, 1)"> ParamDemo {
        </span><span style="color: rgba(0, 0, 255, 1)">public</span> <span style="color: rgba(0, 0, 255, 1)">static</span> <span style="color: rgba(0, 0, 255, 1)">void</span><span style="color: rgba(0, 0, 0, 1)"> main(String[] args) {
            </span><span style="color: rgba(0, 0, 255, 1)">int</span>[] arr = {21,89,32<span style="color: rgba(0, 0, 0, 1)">};
            </span><span style="color: rgba(0, 0, 255, 1)">int</span> sum =<span style="color: rgba(0, 0, 0, 1)"> add(arr);
            System.out.println(sum);
            sum </span>= add(21,89,32);<span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">可变参数调用形式</span><span style="color: rgba(0, 0, 0, 1)">
            System.out.println(sum);
        }
    </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">JDK1.5之后写法</span>
        <span style="color: rgba(0, 0, 255, 1)">public</span> <span style="color: rgba(0, 0, 255, 1)">static</span> <span style="color: rgba(0, 0, 255, 1)">int</span> add(<span style="color: rgba(0, 0, 255, 1)">int</span><span style="color: rgba(0, 0, 0, 1)">...arr){
            </span><span style="color: rgba(0, 0, 255, 1)">int</span> sum = 0<span style="color: rgba(0, 0, 0, 1)">;
            </span><span style="color: rgba(0, 0, 255, 1)">for</span> (<span style="color: rgba(0, 0, 255, 1)">int</span> i = 0; i &lt; arr.length; i++<span style="color: rgba(0, 0, 0, 1)">) {
                sum </span>+=<span style="color: rgba(0, 0, 0, 1)"> arr[i];
            }
            </span><span style="color: rgba(0, 0, 255, 1)">return</span><span style="color: rgba(0, 0, 0, 1)"> sum;
        }
    </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">原始写法</span>
    <span style="color: rgba(0, 128, 0, 1)">/*</span><span style="color: rgba(0, 128, 0, 1)">
    public static int add(int[] arr) {
    int sum = 0;
    for (int i = 0; i &lt; arr.length; i++) {
    sum += arr[i];
    }
    return sum;
    }
    </span><span style="color: rgba(0, 128, 0, 1)">*/</span><span style="color: rgba(0, 0, 0, 1)">
    }</span></pre>
    </div>
    <p>上述add方法在同一个类中，只能存在一个。因为会发生调用的不确定性</p>
    <h4>注意：如果在方法书写时，这个方法拥有多参数，参数中包含可变参数，可变参数一定要写在参数列表的末尾位置。</h4>
    <h2>Collections集合工具类</h2>
    <p>Collections是集合工具类，用来对集合进行操作。部分方法如下：</p>
    <div class="cnblogs_code">
    <pre><span style="color: rgba(0, 0, 255, 1)">public</span> <span style="color: rgba(0, 0, 255, 1)">static</span> &lt;T&gt; <span style="color: rgba(0, 0, 255, 1)">void</span> sort(List&lt;T&gt; list) <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)"> 集合元素排序
    </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">排序前元素list集合元素 [33,11,77,55]</span>
    <span style="color: rgba(0, 0, 0, 1)">Collections.sort( list );
    </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">排序后元素list集合元素 [11,33,55,77]</span>
    <span style="color: rgba(0, 0, 255, 1)">public</span> <span style="color: rgba(0, 0, 255, 1)">static</span> <span style="color: rgba(0, 0, 255, 1)">void</span> shuffle(List&lt;?&gt; list) <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)"> 集合元素存储位置打乱
    </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">list集合元素 [11,33,55,77]</span>
    <span style="color: rgba(0, 0, 0, 1)">Collections.shuffle( list );
    </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">使用shuffle方法后，集合中的元素为[77,33,11,55]，每次执行该方法，集合中存储的元素位置都会随机打乱</span></pre>
    </div>
    <h3>集合嵌套</h3>
    <p>集合嵌套并不是一个新的知识点，仅仅是集合内容又是集合，如Collection集合嵌套、Collection集合与Map集合相互嵌套、Map集合嵌套。</p>
    <p>ArrayList嵌套 ArrayList：ArrayList&lt; ArrayList&lt;String&gt; &gt;、Collection&lt; ArrayList&lt;Integer&gt; &gt;</p>
    <p>Map嵌套 ArrayList：HashMap&lt;String, ArrayList&lt;Person&gt;&gt;、ArrayList&lt; HashMap&lt;String, String&gt;&gt;</p>
    <p>Map集合嵌套：HashMap&lt;String, HashMap&lt;String,String&gt;&gt;、HashMap&lt;String, HashMap&lt;Person,String&gt;&gt;</p>
    <h3>集合继承体系的面向对象思想</h3>
    <p>接口：用来明确所有集合中该具有的功能，相当于在定义集合功能标准；</p>
    <p>抽象类：把多个集合中功能实现方式相同的方法，抽取到抽象类实现，具体集合不再遍写，继承使用即可；</p>
    <p>具体类：继承抽象类，实现接口，重写所有抽象方法，达到具备指定功能的集合。每个具体集合类，根据自身的数据存储结构方式，对接口中的功能方法，进行不同方式的实现。</p>
    <h2>模拟斗地主洗牌发牌</h2>
    <p>案例介绍：按照斗地主的规则，完成洗牌发牌的动作。</p>
    <p>具体规则：</p>
    <ul>
    <li>1. 组装54张扑克牌</li>
    <li>2. 将54张牌顺序打乱</li>
    <li>3. 三个玩家参与游戏，三人交替摸牌，每人17张牌，最后三张留作底牌。</li>
    <li>4. 查看三人各自手中的牌（按照牌的大小排序）、底牌</li>
    <li>手中扑克牌从大到小的摆放顺序：大王,小王,2,A,K,Q,J,10,9,8,7,6,5,4,3</li>
    </ul>
    <p>案例需求分析</p>
    <p>准备牌：</p>
    <ul>
    <li>完成数字与纸牌的映射关系：</li>
    <li>使用双列Map(HashMap)集合，完成一个数字与字符串纸牌的对应关系(相当于一个字典)。</li>
    </ul>
    <p>洗牌：通过数字完成洗牌发牌</p>
    <p>发牌：将每个人以及底牌设计为ArrayList&lt;String&gt;,将最后3张牌直接存放于底牌，剩余牌通过对3取模依次发牌。</p>
    <p>存放的过程中要求数字大小与斗地主规则的大小对应。</p>
    <p>将代表不同纸牌的数字分配给不同的玩家与底牌。</p>
    <p>看牌：</p>
    <p>通过Map集合找到对应字符展示。</p>
    <p>通过查询纸牌与数字的对应关系，由数字转成纸牌字符串再进行展示。</p>
    <p>实现代码步骤：</p>
    <p>首先，要修改java文件编码，由GBK修改为UTF-8，因为默认的字符编码GBK没有我们要的梅花、方片、黑桃、红桃(♠♥♦♣)等特殊字符。</p>
    <div class="cnblogs_code">
    <pre><span style="color: rgba(0, 0, 255, 1)">package</span><span style="color: rgba(0, 0, 0, 1)"> Poker;
    </span><span style="color: rgba(0, 0, 255, 1)">import</span><span style="color: rgba(0, 0, 0, 1)"> java.util.ArrayList;
    
    </span><span style="color: rgba(0, 0, 255, 1)">import</span><span style="color: rgba(0, 0, 0, 1)"> java.util.Collections;
    </span><span style="color: rgba(0, 0, 255, 1)">import</span><span style="color: rgba(0, 0, 0, 1)"> java.util.HashMap;
    
    </span><span style="color: rgba(0, 128, 0, 1)">/*</span><span style="color: rgba(0, 128, 0, 1)">
    * 斗地主洗牌发牌排序
    </span><span style="color: rgba(0, 128, 0, 1)">*/</span>
    <span style="color: rgba(0, 0, 255, 1)">public</span> <span style="color: rgba(0, 0, 255, 1)">class</span><span style="color: rgba(0, 0, 0, 1)"> Poker {
        </span><span style="color: rgba(0, 0, 255, 1)">public</span> <span style="color: rgba(0, 0, 255, 1)">static</span> <span style="color: rgba(0, 0, 255, 1)">void</span><span style="color: rgba(0, 0, 0, 1)"> main(String[] args) {
    </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">准备花色</span>
            ArrayList&lt;String&gt; color = <span style="color: rgba(0, 0, 255, 1)">new</span> ArrayList&lt;String&gt;<span style="color: rgba(0, 0, 0, 1)">();
            color.add(</span>"♠"<span style="color: rgba(0, 0, 0, 1)">);
            color.add(</span>"♥"<span style="color: rgba(0, 0, 0, 1)">);
            color.add(</span>"♦"<span style="color: rgba(0, 0, 0, 1)">);
            color.add(</span>"♣"<span style="color: rgba(0, 0, 0, 1)">);
    </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">准备数字</span>
            ArrayList&lt;String&gt; number = <span style="color: rgba(0, 0, 255, 1)">new</span> ArrayList&lt;String&gt;<span style="color: rgba(0, 0, 0, 1)">();
            Collections.addAll(number,</span>"3","4","5","6","7","8","9","10","J","Q","K","A","2"<span style="color: rgba(0, 0, 0, 1)">);
    </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">定义一个map集合：用来将数字与每一张牌进行对应</span>
            HashMap&lt;Integer, String&gt; map = <span style="color: rgba(0, 0, 255, 1)">new</span> HashMap&lt;Integer, String&gt;<span style="color: rgba(0, 0, 0, 1)">();
            </span><span style="color: rgba(0, 0, 255, 1)">int</span> index = 0<span style="color: rgba(0, 0, 0, 1)">;
            </span><span style="color: rgba(0, 0, 255, 1)">for</span><span style="color: rgba(0, 0, 0, 1)"> (String thisNumber : number) {
                </span><span style="color: rgba(0, 0, 255, 1)">for</span><span style="color: rgba(0, 0, 0, 1)"> (String thisColor : color) {
                    map.put(index</span>++, thisColor+<span style="color: rgba(0, 0, 0, 1)">thisNumber);
                }
            }
    
    </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">加入大小王</span>
            map.put(index++, "小☺"<span style="color: rgba(0, 0, 0, 1)">);
            map.put(index</span>++, "大☻"<span style="color: rgba(0, 0, 0, 1)">);
    </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">一副54张的牌 ArrayList里边为0-53的数的新牌</span>
            ArrayList&lt;Integer&gt; cards = <span style="color: rgba(0, 0, 255, 1)">new</span> ArrayList&lt;Integer&gt;<span style="color: rgba(0, 0, 0, 1)">();
            </span><span style="color: rgba(0, 0, 255, 1)">for</span> (<span style="color: rgba(0, 0, 255, 1)">int</span> i = 0; i &lt;= 53; i++<span style="color: rgba(0, 0, 0, 1)">) {
                cards.add(i);
            }
    </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">洗牌</span>
    <span style="color: rgba(0, 0, 0, 1)">        Collections.shuffle(cards);
    </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">创建三个玩家和底牌</span>
            ArrayList&lt;Integer&gt; iPlayer = <span style="color: rgba(0, 0, 255, 1)">new</span> ArrayList&lt;Integer&gt;<span style="color: rgba(0, 0, 0, 1)">();
            ArrayList</span>&lt;Integer&gt; iPlayer2 = <span style="color: rgba(0, 0, 255, 1)">new</span> ArrayList&lt;Integer&gt;<span style="color: rgba(0, 0, 0, 1)">();
            ArrayList</span>&lt;Integer&gt; iPlayer3 = <span style="color: rgba(0, 0, 255, 1)">new</span> ArrayList&lt;Integer&gt;<span style="color: rgba(0, 0, 0, 1)">();
            ArrayList</span>&lt;Integer&gt; itCards = <span style="color: rgba(0, 0, 255, 1)">new</span> ArrayList&lt;Integer&gt;<span style="color: rgba(0, 0, 0, 1)">();
    </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">遍历这副洗好的牌，遍历过程中，将牌发到三个玩家和底牌中</span>
            <span style="color: rgba(0, 0, 255, 1)">for</span> (<span style="color: rgba(0, 0, 255, 1)">int</span> i = 0; i &lt; cards.size(); i++<span style="color: rgba(0, 0, 0, 1)">) {
                </span><span style="color: rgba(0, 0, 255, 1)">if</span>(i&gt;=51<span style="color: rgba(0, 0, 0, 1)">) {
                    itCards.add(cards.get(i));
                } </span><span style="color: rgba(0, 0, 255, 1)">else</span><span style="color: rgba(0, 0, 0, 1)"> {
                    </span><span style="color: rgba(0, 0, 255, 1)">if</span>(i%3==0<span style="color: rgba(0, 0, 0, 1)">) {
                        iPlayer.add(cards.get(i));
                    }</span><span style="color: rgba(0, 0, 255, 1)">else</span> <span style="color: rgba(0, 0, 255, 1)">if</span>(i%3==1<span style="color: rgba(0, 0, 0, 1)">) {
                        iPlayer2.add(cards.get(i));
                    }</span><span style="color: rgba(0, 0, 255, 1)">else</span><span style="color: rgba(0, 0, 0, 1)"> {
                        iPlayer3.add(cards.get(i));
                    }
                }
            }
    </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">对每个人手中的牌排序</span>
    <span style="color: rgba(0, 0, 0, 1)">        Collections.sort(iPlayer);
            Collections.sort(iPlayer2);
            Collections.sort(iPlayer3);
    </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">对应数字形式的每个人手中的牌，定义字符串形式的牌</span>
            ArrayList&lt;String&gt; sPlayer = <span style="color: rgba(0, 0, 255, 1)">new</span> ArrayList&lt;String&gt;<span style="color: rgba(0, 0, 0, 1)">();
            ArrayList</span>&lt;String&gt; sPlayer2 = <span style="color: rgba(0, 0, 255, 1)">new</span> ArrayList&lt;String&gt;<span style="color: rgba(0, 0, 0, 1)">();
            ArrayList</span>&lt;String&gt; sPlayer3 = <span style="color: rgba(0, 0, 255, 1)">new</span> ArrayList&lt;String&gt;<span style="color: rgba(0, 0, 0, 1)">();
            ArrayList</span>&lt;String&gt; sCards = <span style="color: rgba(0, 0, 255, 1)">new</span> ArrayList&lt;String&gt;<span style="color: rgba(0, 0, 0, 1)">();
            </span><span style="color: rgba(0, 0, 255, 1)">for</span><span style="color: rgba(0, 0, 0, 1)"> (Integer key : iPlayer) {
                sPlayer.add(map.get(key));
            }
            </span><span style="color: rgba(0, 0, 255, 1)">for</span><span style="color: rgba(0, 0, 0, 1)"> (Integer key : iPlayer2) {
                sPlayer2.add(map.get(key));
            }
            </span><span style="color: rgba(0, 0, 255, 1)">for</span><span style="color: rgba(0, 0, 0, 1)"> (Integer key : iPlayer3) {
                sPlayer3.add(map.get(key));
            }
            </span><span style="color: rgba(0, 0, 255, 1)">for</span><span style="color: rgba(0, 0, 0, 1)"> (Integer key : itCards) {
                sCards.add(map.get(key));
            }
    </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">看牌</span>
    <span style="color: rgba(0, 0, 0, 1)">        System.out.println(sPlayer);
            System.out.println(sPlayer2);
            System.out.println(sPlayer3);
            System.out.println(sCards);
        }
    }</span></pre>
    </div>
    <h3>知识点总结</h3>
    <p>Map集合:</p>
    <ul>
    <li>map集合中的元素都是成对出现，成对存储的</li>
    <li>map集合中的元素都是以一对键和值的形式组成存在的，称为键值对，理解为夫妻对</li>
    <li>map集合中的键不能重复存储，值可以重复</li>
    <li>map集合中的每一个键 对应着一个值</li>
    </ul>
    <p>方法：</p>
    <ul>
    <li>V put(K key, V value) 把指定的键与指定的值添加到Map集合中</li>
    <li>V remove(Object key) 把指定的键 所对应的键值对元素 在Map集合中删除，返回被删除元素的值</li>
    <li>Set&lt;Map.Entry&lt;K,V&gt;&gt; entrySet() 获取到Map集合中所有的键值对对象的集合(Set集合)</li>
    <li>V get(Object key) 根据指定的键，在Map集合中获取对应的值</li>
    <li>Set&lt;K&gt; keySet() 获取Map集合中所有的键，存储到Set集合中</li>
    </ul>
    <p>Map集合遍历的两种方式</p>
    <ul>
    <li>方式1：根据键找值的方式</li>
    </ul>
    <div class="cnblogs_code">
    <pre><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">a, 获取到Map集合中所有的键，返回对应的Set集合
    </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">b, 遍历键的集合，获取到每一个键
    </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">c, 通过键，找到对应的值
    </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">获取到Map集合中所有的键，返回对应的Set集合</span><span style="color: rgba(0, 0, 0, 1)">
    Set</span>&lt;String&gt; keys =<span style="color: rgba(0, 0, 0, 1)"> map.keySet();
    </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">遍历键的集合，获取到每一个键</span>
    <span style="color: rgba(0, 0, 255, 1)">for</span><span style="color: rgba(0, 0, 0, 1)"> (String key : keys) {
    </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">通过键，找到对应的值</span><span style="color: rgba(0, 0, 0, 1)">
    Student s </span>=<span style="color: rgba(0, 0, 0, 1)"> map.get(key);
    System.out.println( key </span>+ "..." + s.getName() + "..." +<span style="color: rgba(0, 0, 0, 1)"> s.getAge() );
    }</span></pre>
    </div>
    <ul>
    <li>方式2：根据键值对对象找键和值的方式</li>
    </ul>
    <div class="cnblogs_code">
    <pre><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">a, 获取Map集合中所有的键值对元素,返回对应的Set集合
    </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">b, 遍历键值对元素集合，获取到每一个键值对元素对象
    </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">c, 通过键值对元素对象，获取对应的键，和对应的值
    </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">获取Map集合中所有的键值对元素,返回对应的Set集合</span><span style="color: rgba(0, 0, 0, 1)">
    Set</span>&lt; Map.Entry&lt;String, Student&gt;&gt; entrySet =<span style="color: rgba(0, 0, 0, 1)"> map.entrySet();
    </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">遍历键值对元素集合，获取到每一个键值对元素对象</span>
    <span style="color: rgba(0, 0, 255, 1)">for</span> (Map.Entry&lt;String, Student&gt;<span style="color: rgba(0, 0, 0, 1)"> entry : entrySet) {
    </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">通过键值对元素对象，获取对应的键，和对应的值
    </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">找键</span><span style="color: rgba(0, 0, 0, 1)">
    String key </span>=<span style="color: rgba(0, 0, 0, 1)"> entry.getKey();
    </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">找值</span><span style="color: rgba(0, 0, 0, 1)">
    Student s </span>=<span style="color: rgba(0, 0, 0, 1)"> entry.getValue();
    </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">打印</span><span style="color: rgba(0, 0, 0, 1)">
    System.out.println( key</span>+"..."+s.getName()+"..."+<span style="color: rgba(0, 0, 0, 1)">s.getAge() );
    }</span></pre>
    </div>
    <p>HashMap:</p>
    <p>特点：</p>
    <ul>
    <li>是Map集合的子集合</li>
    <li>底层采用哈希表结构</li>
    <li>HashMap集合中的key不能重复，通过重写hashCode() 与 equals()方法来保证键的唯一。</li>
    <li>不能保证元素存与取的顺序完全一致</li>
    </ul>
    <p>LinkedHashMap:</p>
    <p>特点：</p>
    <ul>
    <li>是HashMap集合的子集合</li>
    <li>底层采用哈希表+链表结构</li>
    <li>key不能重复，通过重写hashCode() 与 equals()方法来保证键的唯一。</li>
    </ul>
    <p>Collections中的方法：</p>
    <ul>
    <li>public static &lt;T&gt; void sort(List&lt;T&gt; list) 排序</li>
    <li>public static void shuffle(List&lt;?&gt; list) 集合中的元素存储位置随机打乱</li>
    </ul>
    </div>

</body>
</html>